package xyz.yuzegod.megawalls.classes.normal.dreadlord;

import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import xyz.yuzegod.megawalls.classes.Classes;
import xyz.yuzegod.megawalls.classes.Skill;
import xyz.yuzegod.megawalls.game.GamePlayer;
import xyz.yuzegod.megawalls.stats.KitStatsContainer;
import xyz.yuzegod.megawalls.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

public class ThirdSkill extends Skill
{
    public ThirdSkill(final Classes classes) {
        super("灵魂吸嗜", classes);
    }
    
    @Override
    public int maxedLevel() {
        return 3;
    }
    
    @Override
    public double getAttribute(final int level) {
        switch (level) {
            case 1: {
                return 0.55;
            }
            case 2: {
                return 0.65;
            }
            case 3: {
                return 0.75;
            }
            default: {
                return 0.55;
            }
        }
    }
    
    public double getSeconds(final int level) {
        switch (level) {
            case 1: {
                return 1.0;
            }
            case 2: {
                return 2.5;
            }
            case 3: {
                return 5.0;
            }
            default: {
                return 1.0;
            }
        }
    }
    
    @Override
    public List<String> getInfo(final int level) {
        final List<String> lore = new ArrayList<String>();
        if (level == 1) {
            lore.add(" §8▪ §7击杀敌人时,获得§a" + StringUtils.percent(this.getAttribute(level)) + "§7伤害加成");
            lore.add("   §7和生命恢复I效果,持续§a" + this.getSeconds(level) + "§7秒。");
            return lore;
        }
        lore.add(" §8▪ §7击杀敌人时,获得§8" + StringUtils.percent(this.getAttribute(level - 1)) + " ➜ §a" + StringUtils.percent(this.getAttribute(level)) + "§7伤害加成");
        lore.add("   §7和生命恢复I效果,持续§8" + this.getSeconds(level - 1) + " ➜ §a" + this.getSeconds(level) + "§7秒。");
        return lore;
    }
    
    @Override
    public void upgrade(final GamePlayer gamePlayer) {
        final KitStatsContainer kitStats = gamePlayer.getPlayerStats().getKitStats(this.getClasses());
        kitStats.addSkill3Level();
    }
    
    @Override
    public int getPlayerLevel(final GamePlayer gamePlayer) {
        return gamePlayer.getPlayerStats().getKitStats(this.getClasses()).getSkill3Level();
    }
    
    @Override
    public boolean use(final GamePlayer gamePlayer, final KitStatsContainer kitStats) {
        final int level = kitStats.getSkill3Level();
        final Player player = gamePlayer.getPlayer();
        if (player.hasPotionEffect(PotionEffectType.INCREASE_DAMAGE)) {
            player.removePotionEffect(PotionEffectType.INCREASE_DAMAGE);
        }
        player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, (int)(this.getSeconds(level) * 20.0), (int)this.getAttribute(level)));
        if (player.hasPotionEffect(PotionEffectType.REGENERATION)) {
            player.removePotionEffect(PotionEffectType.REGENERATION);
        }
        player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, (int)(this.getSeconds(level) * 20.0), 0));
        Dreadlord.skill3.put(gamePlayer, (int)this.getSeconds(level));
        return true;
    }
    
    @Override
    public String getSkillTip(final GamePlayer gamePlayer) {
        if (Dreadlord.skill3.getOrDefault(gamePlayer, 0) == 0) {
            return null;
        }
        final int level = this.getPlayerLevel(gamePlayer);
        final String percent = StringUtils.percent(this.getAttribute(level));
        final int seconds = (int)this.getSeconds(level);
        return this.getClasses().getNameColor() + "§l" + this.getName() + " §c§l" + percent + " " + seconds + "秒";
    }
}
